<template>
  <div class="home">
    <div class="nav">
      <home-nav class="home_nav" @tab="tab"></home-nav>
    </div>
    <div class="box">
      <!-- 关注 -->
      <ul class="gz" v-if="num == 1">
        <li>
          <gz-note></gz-note>
          <gz-note src="1.jpg"></gz-note>
          <gz-note></gz-note>
          <gz-note src="1.jpg"></gz-note>
        </li>
      </ul>
      <!-- 发现 -->
      <ul v-show="num == 2">
        <li>
          <note v-for="item in note1" :key="item.id" :note="item"></note>
        </li>
        <li>
          <note v-for="item in note2" :key="item.id" :note="item"></note>
        </li>
      </ul>
      <!-- 位置 -->
      <ul v-show="num == 3">
        <li>
          <note>
            <template #icon>
              <div class="like">
                <van-icon name="location-o" size="15"></van-icon>
                <!-- 距离 -->
                <span class="num">{{ 999 }}m</span>
              </div>
            </template>
          </note>
          <note></note>
          <note></note>
          <note></note>
        </li>
        <li>
          <note></note>
          <note></note>
          <note></note>
          <note></note>
          <note></note>
          <note></note>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import Note from "@/components/Note.vue";
import HomeNav from "@/components/HomeNav.vue";
import GzNote from "@/components/GzNote.vue";
export default {
  name: "Home",
  components: {
    Note,
    HomeNav,
    GzNote,
  },
  data() {
    return {
      // 控制tab显示
      num: 2,
      note1: [],
      note2: [],
    };
  },
  mounted() {
    let noteList = this.$store.state.noteList;
    if(noteList.length!=0){
      for (let i = 0; i < noteList.length; i++) {
      if (i < noteList.length / 2) {
        this.note1.push(noteList[i]);
      } else {
        this.note2.push(noteList[i]);
      }
    }
    }
  },
  methods: {
    // 自定义tab事件传给nav子组件
    tab(i) {
      this.num = i;
    },
  },
};
</script>
<style lang="scss" scoped>
.home {
  width: 100vw;
  .nav {
    width: 100vw;
    height: 45px;

    .home_nav {
      position: fixed;
      top: 0;
      left: 0;
      z-index: 99;
    }
  }

  .box {
    // 预留底部导航位置
    

    ul {
      width: 100%;
      display: flex;
      justify-content: space-evenly;
      li {
        display: flex;
        flex-direction: column;
      }
    }

    .gz {
      display: block;

      li {
        display: block;
      }
    }
  }
}
</style>